﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Core;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.IO;

namespace Yuanlin.Business
{
    public class CompanyShopEditControl : YuanlinUserControl,
        IReplyConverter<CompanyShopReply, GetOperation>
    {
        protected ValuedEditor descriptionValuedEditor;

        protected IButton SaveButton;
        protected IButton BackButton;
        private CompanyShop companyShop;

        public override void GetRequests(List<BaseRequestBinder> requestBinders)
        {
            requestBinders.Add(RequestHelper.BuildGetCompanyShopRequest(this));
        }
        protected override void OnLoad(EventArgs e)
        {
            SaveButton.Click += new EventHandler(SaveButton_Click);
            BackButton.Click += new EventHandler(BackButton_Click);
        }

        private void Bind()
        {
            if(companyShop!=null)
            {
                this.descriptionValuedEditor.Value = companyShop.Body.Value;
            }   
        }

        public void BackButton_Click(object sender, EventArgs e)
        {
            PageRedirect();
        }

        public void SaveButton_Click(object sender, EventArgs e)
        {
            if (companyShop != null)
            {
                companyShop.Body.Value =  CensorWordManager.CensorWord(this.descriptionValuedEditor.Value);

                BusinessManager.UpdateCompanyShop(companyShop);
            }
            PageRedirect();
        }
        private void PageRedirect()
        {
            Page.Response.Redirect(SiteUrls.Instance().GetCompanyShopListUrl());
        }

        #region IReplyConverter<CompanyShopReply,GetOperation> Members

        public void ConvertReply(CompanyShopReply reply, GetOperation operation)
        {
            if (reply != null)
            {
                companyShop = reply.Entity as CompanyShop;

                if (!Page.IsPostBack)
                {
                    Bind();
                }
            }
        }

        #endregion
    }
}